package activity.addCamera;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.hichip.campro.R;
import base.HiActivity;
import butterknife.BindView;
import common.HiDataValue;
import common.TitleView;
import main.MainActivity;

/**
 * 确认AP设备的界面  （当前手机连接为ap热点 点击新设备并搜到ap机器）
 * Created by lt on 2018\3\9 0009.
 */

public class ConfirmApDeviceActivity extends HiActivity implements View.OnClickListener {
    @BindView(R.id.title) TitleView title;
    @BindView(R.id.but_application) Button but_application;
    @BindView(R.id.tv_uid) TextView tv_uid;
    private String mUid;
    private String mSsid;
    private String mCurrentPhoneWiFi;

    @Override
    protected int setLayoutId() {
        return R.layout.activity_confirm_ap_device;
    }

    @Override
    protected void init(@Nullable Bundle savedInstanceState) {
        getIntentData();
        initViewAndData();
        setListeners();

    }

    private void getIntentData() {
        mUid=getIntent().getStringExtra(HiDataValue.EXTRAS_KEY_UID);
        mSsid=getIntent().getStringExtra("ssid");
        mCurrentPhoneWiFi=getIntent().getStringExtra("mCurrentPhoneWiFi");
    }

    private void setListeners() {
        but_application.setOnClickListener(this);
    }

    private void initViewAndData() {
        title.setTitle(getString(R.string.title_ap_device));
        title.setButton(TitleView.NAVIGATION_BUTTON_LEFT);
        title.setRightTxtBack(R.mipmap.x_bule);
        title.setNavigationBarButtonListener(new TitleView.NavigationBarButtonListener() {
            @Override
            public void OnNavigationButtonClick(int which) {
                switch (which) {
                    case TitleView.NAVIGATION_BUTTON_LEFT:
                        ConfirmApDeviceActivity.this.finish();
                        break;
                    case TitleView.NAVIGATION_BUTTON_IV_RIGHT:
                        Intent intent=new Intent(ConfirmApDeviceActivity.this, MainActivity.class);
                        intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                        startActivity(intent,true);
                        break;
                }
            }
        });
        if(!TextUtils.isEmpty(mUid)){
            tv_uid.setText(mUid);
        }
    }


    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.but_application:
                Intent intent=new Intent(ConfirmApDeviceActivity.this,AddAndConfigWiFiActivity.class);
                if(!TextUtils.isEmpty(mUid)){
                    intent.putExtra(HiDataValue.EXTRAS_KEY_UID,mUid);
                }
                intent.putExtra("ssid",mSsid);
                intent.putExtra("type",2);
                intent.putExtra("isAP",true);
                intent.putExtra("mCurrentPhoneWiFi",mCurrentPhoneWiFi);
                startActivity(intent);
                break;
        }

    }
}
